package com.jeecms.wicool.dao.orders.impl;


import java.util.List;

import org.springframework.stereotype.Repository;

import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.orders.OrderProductMappingDao;
import com.jeecms.wicool.entity.orders.OrderProductMapping;

@Repository
public class OrderProductMappingDaoImpl extends HibernateBaseDao<OrderProductMapping, Integer>
		implements OrderProductMappingDao {

	@Override
	protected Class<OrderProductMapping> getEntityClass() {
		// TODO Auto-generated method stub
		return OrderProductMapping.class;
	}
	@Override
	public Pagination getPage(Integer dingdanId,int pageNo, int pageSize) {
		Finder f = Finder.create("select bean from OrderProductMapping bean where 1=1 ");
		
		if (null!=dingdanId){
			f.append(" and bean.dingdan.id = :dingdanId");
			f.setParam("dingdanId",dingdanId);
		}
		f.append(" order by bean.id desc");
		return find(f, pageNo, pageSize);
	}
	@Override
	public OrderProductMapping findById(Integer id) {
		OrderProductMapping entity = get(id);
		return entity;
	}
	
	@Override
	public List<OrderProductMapping> getAll() {
		Finder f= Finder.create("select bean from OrderProductMapping bean");
		f.append(" order by bean.id desc");
		return find(f);
	}
	@Override
	public List<OrderProductMapping> getByOrderId(Integer orderId) {
		Finder f= Finder.create("select bean from OrderProductMapping bean where bean.dingdan.id="+orderId);
		f.append(" order by bean.id desc");
		return find(f);
	}
}